package com.example.runningdemo.designModel;

/**
 * @program: Running-Demo
 * @description: 懒汉模式
 * @author: kangwei
 * @create: 2024-08-07 09:05
 **/

public class LazySingleton {

    // 定义静态对象变量
    private static LazySingleton INSTANCE;

    // 私有构造方法
    private LazySingleton() {
    }

    // 获取实例对象 synchronized 懒汉模式关键字
    public static synchronized LazySingleton getInstance() {
        if (null == INSTANCE) {
            return new LazySingleton();
        }
        return INSTANCE;
    }

    public static void main(String[] args) {
        System.out.println(getInstance());
    }
}
